package files_controller;
import java.io.*;

public class Tree implements ICommandExecutor{
	
	int nest = 1;
			
	public void execute(String folderName){
		String[] str_mas = folderName.split(" ");
		String path = str_mas[1];
		inner_execute(path);				
	}
	
	private void inner_execute(String path){
		File folder = new File(path);
		if (!folder.exists()){
			System.out.println("Directory not found: " + path);			
		}else{
			StringBuilder gap = new StringBuilder();
			for (int i = 0; i < nest; i++){
				gap.append(' ');
		   }
			File[] list = folder.listFiles();
			for(File file : list){
				if(file.isDirectory()){
					System.out.println(gap.toString() + "[+]" + file.getName());
					nest = nest+1;
					inner_execute(file.toString());
				}else {System.out.println(gap.toString() + file.getName());}
			}
		}			
	}		
}
